﻿using CardMaker.Library.Models;
using System.Text.Encodings.Web;
using System.Text.Json;

namespace CardMaker.Library.Services;

public class TextFrameStorage : ITextFrameStorage
{
    public async Task<IList<TextFrame>> GetTextFramesAsync(CardTemplate cardTemplate)
    {
        var options = new JsonSerializerOptions
        {
            WriteIndented = true, //大小写区分
            Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping //解决中文乱码
        };
        var textFrames = JsonSerializer.Deserialize<List<TextFrame>>(cardTemplate.TextFrames, options);//反序列化

        return textFrames ?? new List<TextFrame>();
    }

    //卡片文本框随卡片保存无需单独写保存方法
    public Task SaveTextFramesAsync(TextFrame textFrame)
    {
        throw new NotImplementedException();
    }
}